package com.mobilezu.mobile.pushserver.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import net.sf.json.JSONObject;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name = "tb_push_user")
public class PushUser implements Serializable {

	private static final long serialVersionUID = 4733464888738356502L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "username", nullable = false, length = 64, unique = true)
	private String username;

	@Column(name = "password", length = 64)
	private String password;

	@Column(name = "name", length = 64)
	private String name;

	@Column(name = "email", length = 64)
	private String email;

	@Column(name = "created_date", length = 32)
	private String createdDate;

	@Column(name = "updated_date", length = 32)
	private String updatedDate;

	@Column(name = "admin", length = 8)
	private String admin = "0";

	@Transient
	private boolean online;

	public PushUser() {
	}

	public PushUser(final String username) {
		this.username = username;
	}

	public PushUser(String username, String password, String name,
			String email, String createdDate, String updatedDate) {
		this.username = username;
		this.password = password;
		this.name = name;
		this.email = email;
		this.createdDate = createdDate;
		this.updatedDate = updatedDate;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isOnline() {
		return online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	public void setAdmin(String admin) {
		this.admin = admin;
	}

	public String getAdmin() {
		return admin;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof PushUser)) {
			return false;
		}
		final PushUser obj = (PushUser) o;
		if (username != null ? !username.equals(obj.username)
				: obj.username != null) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

	public void setCreatedDate(String createdDate) {
		this.createdDate = createdDate;
	}

	public String getCreatedDate() {
		return createdDate;
	}

	public void setUpdatedDate(String updatedDate) {
		this.updatedDate = updatedDate;
	}

	public String getUpdatedDate() {
		return updatedDate;
	}
	
	public JSONObject toJSONObject(){
		JSONObject obj=new JSONObject();
		obj.put("id", id);
		obj.put("name", name);
		obj.put("password",password);
		obj.put("username",username);
		obj.put("email", email);
		obj.put("created_date", createdDate);
		obj.put("updated_date", updatedDate);
		obj.put("admin", admin);
		obj.put("online", online);
		return obj;
	}
	
}
